import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class OR here.
 * 
 * @author Christian Pérez Zavalija
 * @version 25-Jun-2013
 */
public class OR extends Circuit
{
    private GreenfootImage imgOr;
    
    /**
     * Load image and displays.
     */
    public OR()
    {
        imgOr=new GreenfootImage("OR.png");
        setImage(imgOr);
    }
    
    
    /**
     * The image is scale in 50%
     */
    public void scale()
    {
        imgOr.scale(imgOr.getWidth()-50,imgOr.getHeight()-40);
    }
    
    /**
     * It drives the circuit logic OR(7432) in the input pins for establish a charge on the respective output pin.
     * 
     * @param into number pinA and number pin B.
     */
    public void logicOR(int A, int B)
    {
        if(pins[A].charge==0&&pins[B].charge==0)
            pins[B+1].charge=0;
        else
            pins[B+1].charge=1;
    }
    
    /**
     * Method calls the act () of its superclass. Check if the circuit is energized and if the
     * values ​​of the input pins are different garbage charge.
     */
    public void act() 
    {
        super.act();
        if(pins[6].charge==0&&pins[7].charge==1){
            if(pins[0].charge<2&&pins[1].charge<2)
                this.logicOR(0,1);
            if(pins[3].charge<2&&pins[4].charge<2)
                this.logicOR(3,4);
            if(pins[11].charge<2&&pins[12].charge<2)
                this.logicOR(11,12);
            if(pins[8].charge<2&&pins[9].charge<2)
                this.logicOR(8,9);
        }
    }    
}
